home *** CD-ROM | disk | FTP | other *** search
/ Sun Java Desktop System - Live Demo / Sun Java Desktop System - Live Demo.iso / base / boot.img / MINIROOT.GZ / miniroot.ext2 / linuxrc < prev    next >
Encoding:
Text File  |  2003-08-26  |  14.3 KB  |  452 lines

  1. #!/static/sh
  2. #
  3. # KNOPPIX General Startup Script
  4. # (C) Klaus Knopper <knoppix@knopper.net>
  5. # Adapted for the Morphix Base image (www.morphix.org)
  6. # by Alex de Landgraaf <alextreme@xs4all.nl>
  7. #
  8. #
  9. # This script needs some of the builtin ash commands (if, test, ...)
  10. # mount/umount, insmod/rmmod are also a builtin in ash-knoppix.
  11. #
  12.  
  13. # hardcoded configurable options
  14. # Default maximum size of dynamic ramdisk in kilobytes
  15. RAMSIZE=1000000
  16. # End of options
  17.  
  18. # Don't allow interrupt signals
  19. trap "" 1 2 3 15
  20.  
  21. # "Safe" SCSI modules in the right order for autoprobe
  22. # Warning: The sym53c8xx.o and g_NCR* cause a kernel Oops if no such adapter
  23. # is present.
  24. #
  25. # NB: It looks like that ncr53c8xx.o is more stable than 53c7,8xx.o for
  26. # a ncr53c810 controller (at least on my installation box it's more
  27. # immune to SCSI timeouts)
  28. # Removed 53c7,8xx -> crashes if no device attached.
  29. # Removed AM53C974 -> crashes tmscsim if adapter found
  30. # Added initio.o on request (untested)
  31. SCSI_MODULES="aic7xxx.o BusLogic.o \
  32. ncr53c8xx.o NCR53c406a.o \
  33. initio.o \
  34. advansys.o aha1740.o aha1542.o aha152x.o \
  35. atp870u.o dtc.o eata.o fdomain.o gdth.o \
  36. megaraid.o pas16.o pci2220i.o pci2000.o psi240i.o \
  37. qlogicfas.o qlogicfc.o qlogicisp.o \
  38. seagate.o t128.o tmscsim.o u14-34f.o ultrastor.o wd7000.o \
  39. a100u2w.o 3w-xxxx.o"
  40.  
  41. # Misc functions
  42.  
  43. mountit(){
  44. # Usage: mountit src dst "options"
  45. # Uses builtin mount of ash.knoppix
  46. # Builin filesystems
  47. BUILTIN_FS="iso9660 ext2 vfat"
  48. for fs in $BUILTIN_FS; do
  49. test -b $1 && mount -t $fs $3 $1 $2 >/dev/null 2>&1 && return 0
  50. done
  51. return 1
  52. }
  53.  
  54. FOUND_SCSI=""
  55. FOUND_MORPHIX=""
  56. INTERACTIVE=""
  57.  
  58. # Clean input/output
  59. exec >/dev/console </dev/console 2>&1
  60.  
  61. # Reset fb color mode
  62. RESET="]R"
  63. # ANSI COLORS
  64. # Erase to end of line
  65. CRE=""
  66. # Clear and reset Screen
  67. CLEAR="c"
  68. # Normal color
  69. NORMAL=""
  70. # RED: Failure or error message
  71. RED=""
  72. # GREEN: Success message
  73. GREEN=""
  74. # YELLOW: Descriptions
  75. YELLOW=""
  76. # BLUE: System mesages
  77. BLUE=""
  78. # MAGENTA: Found devices or drivers
  79. MAGENTA=""
  80. # CYAN: Questions
  81. CYAN=""
  82. # BOLD WHITE: Hint
  83. WHITE=""
  84.  
  85. # Clear screen with colormode reset
  86. # echo "$CLEAR$RESET"
  87. # echo "$CLEAR"
  88. # Just go to the top of the screen
  89. # echo -n "H"
  90. echo ""
  91. # Be verbose
  92. echo "${WHITE}Welcome to the ${YELLOW}MORPHIX${WHITE} liveCD!${NORMAL}"
  93. echo ""
  94. echo ""
  95.  
  96. # We only need the builtin commands and /static at this point
  97. PATH=/static
  98. export PATH
  99.  
  100. umask 022
  101.  
  102. # Mount /proc and /dev/pts
  103. mount -t proc none /proc
  104. mount -t devpts none /dev/pts
  105.  
  106. # Read boot command line with builtin cat command (shell read function fails in Kernel 2.4.19-rc1)
  107. CMDLINE="$(cat /proc/cmdline)"
  108.  
  109. # Check if we are in interactive startup mode
  110. case "$CMDLINE" in *BOOT_IMAGE=expert\ *) INTERACTIVE="yes"; :>/interactive; ;; esac
  111. # patch from Fabian's linuxrc_modules-disk.diff patch, 2003-07-28
  112. case "$CMDLINE" in *modules-disk*) INTERACTIVE="yes"; ;; esac
  113. NOCD=""
  114. case "$CMDLINE" in *fromhd*) NOCD="yes"; ;; esac
  115. # Does the user want to skip scsi detection?
  116. NOSCSI=""
  117. case "$CMDLINE" in *noscsi*) NOSCSI="yes"; ;; esac
  118.  
  119. case "$CMDLINE" in *splash*) SPLASH="yes"; ;; esac
  120.  
  121. # Bootsplash by Eadz at eadz.co.nz
  122. if test -n "$SPLASH"; then
  123. #exec /static/fbresolution
  124. splash -s -u 0 /bootsplash/config/bootsplash-1024x768.cfg 2>&1 > /dev/null
  125. #/static/splash -s -u 1 /splash/bootsplash-800x600.cfg 2>&1 > /dev/null 
  126. #/static/splash -s -u 2 /splash/bootsplash-800x600.cfg 2>&1 > /dev/null
  127. #/static/splash -s -u 3 /splash/bootsplash-800x600.cfg 2>&1 > /dev/null
  128. #/static/splash -s -u 4 /splash/bootsplash-800x600.cfg 2>&1 > /dev/null 
  129. fi
  130.  
  131. # Do we try to load Base onto ramdisk
  132. #case "$CMDLINE" in *basetoram*) BASETORAM="yes"; ;; esac
  133.  
  134. # Disable kernel messages while probing modules in autodetect mode
  135. echo "0" > /proc/sys/kernel/printk
  136.  
  137. # Mount module disk
  138. mountmodules(){
  139. TYPE="$1"; shift
  140. echo -n "${CRE}${CYAN}Please insert ${TYPE} modules disk and hit Return. ${NORMAL}"
  141. read a
  142. echo -n "${CRE}${BLUE}Mounting ${TYPE} modules disk... ${NORMAL}"
  143. # We always mount over /modules/scsi (because it's there ;-)
  144. if mountit /dev/fd0 /modules/scsi "-o ro"; then
  145. echo "${GREEN}OK.${NORMAL}"
  146. return 0
  147. fi
  148. echo "${RED}NOT FOUND.${NORMAL}"
  149. return 1
  150. }
  151.  
  152. # Unmount module disk
  153. umountmodules(){
  154. TYPE="$1"; shift
  155. echo -n "${CRE}${BLUE}Unmounting ${TYPE} modules disk... ${NORMAL}"
  156. umount /modules/scsi 2>/dev/null
  157. echo "${GREEN}DONE.${NORMAL}"
  158. }
  159.  
  160. # Ask user for modules
  161. askmodules(){
  162. TYPE="$1"; shift
  163. echo "${BLUE}${TYPE} modules available:${WHITE}"
  164. c=""; for m in "$@"; do
  165. if test -f "/modules/scsi/$m"; then
  166. test -z "$c"  && { echo -n "    $m"; c="1"; } || { echo "        $m"; c=""; }
  167. fi
  168. done
  169. [ -n "$c" ] && echo ""
  170. echo "${CYAN}Load ${TYPE} Modules?${NORMAL}"
  171. echo "${CYAN}[Enter full filename(s) (space-separated), Return for autoprobe, ${WHITE}n${CYAN} for none] ${NORMAL}"
  172. echo -n "${CYAN}insmod module(s)> ${NORMAL}"
  173. read MODULES
  174. case "$MODULES" in n|N) MODULES=""; ;; y|"")  MODULES="$*"; ;; esac
  175. }
  176.  
  177. # Try to load the given modules (full path or current directory)
  178. loadmodules(){
  179. TYPE="$1"; shift
  180. test -n "$INTERACTIVE" && echo "6" > /proc/sys/kernel/printk
  181. for i in "$@"; do
  182. echo -n "${CRE}${BLUE}Probing ${TYPE}... ${MAGENTA}$i${NORMAL}"
  183. if test -f /modules/scsi/$i && insmod -f /modules/scsi/$i >/dev/null 2>&1
  184. then
  185. echo "${CRE} ${GREEN}Found ${TYPE} device(s) handled by ${MAGENTA}$i${GREEN}.${NORMAL}"
  186. case "$TYPE" in scsi|SCSI) FOUND_SCSI="yes"; ;; esac
  187. fi
  188. done
  189. test -n "$INTERACTIVE" && echo "0" > /proc/sys/kernel/printk
  190. echo -n "${CRE}"
  191. }
  192.  
  193. # Check for SCSI, use modules on bootfloppy first
  194. if test -n "$INTERACTIVE"; then
  195. # Let the user select interactively
  196. askmodules SCSI $(cd /modules/scsi; echo *.o)
  197. else
  198. # these are the autoprobe-safe modules
  199. MODULES="$SCSI_MODULES"
  200. fi
  201. test -z "$NOSCSI" && test -n "$MODULES" && loadmodules SCSI $MODULES
  202. # End of SCSI check
  203.  
  204. # Check for misc modules in expert mode
  205. if test -n "$INTERACTIVE"; then
  206. another=""; answer=""
  207. while test "$answer" != "n" -a "$answer" != "N"; do
  208. echo -n "${CYAN}Do you want to load additional modules from$another floppy disk? [${WHITE}Y${CYAN}/n] ${NORMAL}"
  209. another=" another"
  210. read answer
  211. case "$answer" in n*|N*) break; ;; esac
  212. if mountmodules new; then
  213. askmodules new $(cd /modules/scsi; echo *.o)
  214. test -n "$MODULES" && loadmodules new $MODULES
  215. umountmodules current
  216. fi
  217. done
  218. fi
  219. # All interactively requested modules should be loaded now.
  220.  
  221. # Check for ide-scsi supported CD-Roms et al.
  222. test -f /proc/scsi/scsi && FOUND_SCSI="yes"
  223.  
  224. # Disable kernel messages again
  225. echo "0" > /proc/sys/kernel/printk
  226.  
  227. # Now that the right SCSI driver is (hopefully) loaded, try to find CDROM
  228. DEVICES="/dev/hd?"
  229. test -n "$FOUND_SCSI" -a -z "$NOCD" && DEVICES="/dev/scd? /dev/scd?? $DEVICES"
  230. # New: Also try parallel port CD-Roms [for Mike].
  231. DEVICES="$DEVICES /dev/pcd?"
  232. # New: also check HD partitions for a MORPHIX/MORPHIX image
  233. test -n "$FOUND_SCSI" && DEVICES="$DEVICES /dev/sd?[1-9] /dev/sd?[1-9][0-9]"
  234. DEVICES="$DEVICES /dev/hd?[1-9] /dev/hd?[1-9][0-9]"
  235. for i in $DEVICES
  236. do
  237. echo -n "${CRE}${BLUE}Looking for CDROM in: ${MAGENTA}$i${NORMAL}   "
  238. if mountit $i /cdrom "-o ro" >/dev/null 2>&1
  239. then
  240. if test -d /cdrom/base
  241. then
  242. echo -n "${CRE} ${GREEN}Accessing MORPHIX CDROM at ${MAGENTA}$i${GREEN}...${NORMAL}"
  243. FOUND_MORPHIX="$i"
  244. break
  245. fi
  246. umount /cdrom
  247. fi
  248. done
  249.  
  250. # Harddisk-installed script part version has been removed
  251. # (MORPHIX can be booted directly from HD now).
  252.  
  253.     if test -n "$FOUND_MORPHIX" -a -f /cdrom/base/morphix; then
  254. # DEBUG
  255. # echo "6" > /proc/sys/kernel/printk
  256.     insmod -f /modules/cloop.o file=/cdrom/base/morphix
  257.     mountit /dev/cloop /MorphixCD "-o ro" || FOUND_MORPHIX=""
  258.     fi
  259.  
  260. # COPYTORAM copied (ironic, isn't it?) from Fabian's linuxrc.rampatch 2003-07-26
  261. COPYTOHD=""
  262. COPYTO=""
  263. COPYTORAM=""
  264.  
  265. case "$CMDLINE" in *toram*) COPYTO="yes"; COPYTORAM="yes"; ;; esac
  266. case "$CMDLINE" in *tohd=*) COPYTO="yes"; COPYTOHD="yes"; ;; esac
  267.  
  268. # Copy the whole cdrom to ram ?
  269. if  test -n "$COPYTO"; 
  270. then 
  271.   # Pre-test if everything succeeded. 
  272.   if test -n "$FOUND_MORPHIX" 
  273.   then 
  274.     # copy library cache 
  275.     cat /MorphixCD/etc/ld.so.cache > /etc/ld.so.cache 
  276.     echo "" 
  277.  
  278.     echo "Copying /cdrom to RamDisk/Harddisk, please be patient..." # Hey, we could use some fancy dialog skript here :-)) 
  279.     /bin/mkdir /cdrom2
  280.     if [ -n "$COPYTORAM" ]
  281.     then
  282.     /bin/mount -t tmpfs -o size=800M /dev/shm /cdrom2
  283.     /bin/cp -a /cdrom/* /cdrom2 # Copy everything to /cdrom2; yes we need more things then only the KNOPPIX/Morphix image, we don't want to produce problems we hadn't before, do we ? (note from Alex: this also copies any modules on the cdrom. Gotta love this patch :)
  284.     else
  285.     COPYTOHD=$(echo $CMDLINE | /usr/bin/tr ' ' '\n' | /bin/sed -n '/tohd=/s/.*=//p' | /usr/bin/tail -1)
  286.     echo -n "${CRE} ${GREEN}Copying Morphix CDROM to ${MAGENTA}/dev/$COPYTOHD${GREEN}... Please be patient. ${NORMAL}"
  287.     if mountit /dev/$COPYTOHD /cdrom2 >/dev/null 2>&1
  288.         then
  289.         /bin/cp -a /cdrom/* /cdrom2
  290.        #/bin/mount -o remount,ro /dev/$COPYTOHD /cdrom2
  291.     else
  292.         echo "${CRE} ${RED}Copying KNOPPIX CDROM failed. /dev/$COPYTOHD is not mountable. ${NORMAL}"
  293.     fi
  294.     fi
  295.     umount /MorphixCD # unmount it
  296.     echo "6" > /proc/sys/kernel/printk # Debugging
  297.     rmmod cloop # release CD
  298.     echo "0" > /proc/sys/kernel/printk # Debugging
  299.     umount /cdrom  # unmount CD
  300.     if test -f /cdrom2/base/morphix; then
  301.       insmod -f /modules/cloop.o file=/cdrom2/base/morphix
  302.       mountit /dev/cloop /MorphixCD "-o ro" || FOUND_MORPHIX="" # if everything else did suceeded so far, this will hopefully succeed too
  303.     else
  304.       FOUND_MORPHIX=""
  305.     fi
  306.   fi 
  307. fi 
  308.  
  309.  
  310. # Final test if everything succeeded.
  311. if test -n "$FOUND_MORPHIX"
  312. then
  313. # copy library cache
  314. cat /MorphixCD/etc/ld.so.cache > /etc/ld.so.cache
  315. echo ""
  316.  
  317. # Enable kernel messages
  318. echo "6" > /proc/sys/kernel/printk
  319.  
  320. # Set paths
  321. echo -n "${CRE}${BLUE}Setting paths...${NORMAL}"
  322. PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:."
  323. export PATH
  324.  
  325. # Debian weirdness
  326. /bin/cp -a /MorphixCD/etc/alternatives /etc/ 2>/dev/null
  327.  
  328. # From here, we should have all essential commands available.
  329. hash -r
  330.  
  331. # Did we copy from ram ? 
  332. if  test -n "$COPYTO"; 
  333. then 
  334.   rmdir /cdrom 
  335.   ln -s /cdrom2 /cdrom # make a symlink and go on to normal boot 
  336. fi
  337.  
  338. # Clean up /
  339. rm -rf /modules #/static
  340.  
  341. # New in Kernel 2.4.x: tempfs with variable ramdisk size.
  342. # We check for available memory anyways and limit the ramdisks
  343. # to a reasonable size.
  344. FOUNDMEM="$(awk '/MemTotal/{print $2}' /proc/meminfo)"
  345. TOTALMEM="$(awk 'BEGIN{m=0};/MemFree|Cached/{m+=$2};END{print m}' /proc/meminfo)"
  346.  
  347. # Be verbose
  348. echo "${CRE}${BLUE}Total memory found: ${YELLOW}${FOUNDMEM}${BLUE} kB${NORMAL}"
  349.  
  350. # Now we need to use a little intuition for finding a ramdisk size
  351. # that keeps us from running out of space, but still doesn't crash the
  352. # machine due to lack of Ram
  353.  
  354. # Minimum size of additional ram partitions
  355. MINSIZE=2000
  356. # At least this much memory minus 30% should remain when home and var are full.
  357. MINLEFT=16000
  358. # Maximum ramdisk size
  359. MAXSIZE="$(expr $TOTALMEM - $MINLEFT)"
  360. # Default ramdisk size for ramdisk
  361. RAMSIZE="$(expr $TOTALMEM / 5)"
  362.  
  363. # Check for sufficient memory to mount extra ramdisk for /home + /var
  364. if test -n "$TOTALMEM" -a "$TOTALMEM" -gt "$MINLEFT"; then
  365. test -z "$RAMSIZE" && RAMSIZE=1000000
  366. mkdir -p /ramdisk
  367. # tmpfs/varsize version, can use swap
  368. RAMSIZE=$(expr $RAMSIZE \* 4)
  369. echo -n "${CRE}${BLUE}Creating ${YELLOW}/ramdisk${BLUE} (dynamic size=${RAMSIZE}k) on ${MAGENTA}/dev/shm${BLUE}...${NORMAL}"
  370. # We need /bin/mount here for the -o size= option
  371. /bin/mount -t tmpfs -o "size=${RAMSIZE}k" /dev/shm /ramdisk && mkdir -p /ramdisk/home /ramdisk/var && ln -s /ramdisk/home /ramdisk/var /
  372. echo "${BLUE}Done.${NORMAL}"
  373. else
  374. mkdir -p /home /var
  375. fi
  376.  
  377. echo -n "${CRE}${BLUE}Creating directories and symlinks on ramdisk...${NORMAL}"
  378. # Create common WRITABLE (empty) dirs
  379. mkdir -p /var/run /var/backups /var/local /var/lock/news \
  380.          /var/nis /var/preserve /var/state/misc /var/tmp /var/lib \
  381.      /var/spool/cups/tmp \
  382.          /mnt/cdrom /mnt/floppy /mnt/hd /mnt/test \
  383.          /home/morph /home/root /etc/sysconfig /etc/X11 
  384. chown morph.morph /home/morph
  385. # Create empty utmp and wtmp
  386. :> /var/run/utmp
  387. :> /var/run/wtmp
  388. # All files in here should be size zero after Morphix.clean was run
  389. cp -a /MorphixCD/var/local /MorphixCD/var/log \
  390.       /MorphixCD/var/spool /var/ 2>/dev/null
  391. cp -a /MorphixCD/var/lib/nfs /MorphixCD/var/lib/xkb /MorphixCD/var/lib/isdn \
  392.       /MorphixCD/var/lib/pcmcia \
  393.       /var/lib/ 2>/dev/null
  394. # Problematic directories in /var/lib (lots and lots of inodes)
  395. ln -s /MorphixCD/var/lib/dpkg /MorphixCD/var/lib/apt \
  396.       /MorphixCD/var/lib/scrollkeeper \
  397.       /var/lib/ 2>/dev/null
  398. # Debian-apt
  399. ln -s /MorphixCD/var/cache/apt /var/cache/ 2>/dev/null
  400. ln -s /MorphixCD/etc/skel /etc/dhcpc/resolv.conf \
  401.       /etc/ 2>/dev/null
  402. ln -s /MorphixCD/dev/* /dev/ 2>/dev/null
  403. # Index files can be HUGE, so better replace cache/man tree by links later
  404. # cp -a /MorphixCD/var/cache/man /var/cache/ 2>/dev/null
  405. # Create links from CDROM for UNWRITABLE (remaining) files
  406. cp -aus /MorphixCD/var/* /var/ 2>/dev/null
  407. cp -aus /MorphixCD/etc/* /etc/ 2>/dev/null
  408. # Make SURE that these are files, not links!
  409. rm -rf /etc/passwd /etc/shadow /etc/group \
  410.        /etc/ppp /etc/isdn /etc/ssh /etc/ioctl.save \
  411.        /etc/inittab /etc/network /etc/sudoers \
  412.        /etc/init /etc/localtime /etc/dhcpc /etc/pnm2ppa.conf 2>/dev/null
  413. cp -a /MorphixCD/etc/passwd /MorphixCD/etc/shadow /MorphixCD/etc/group \
  414.       /MorphixCD/etc/ppp /MorphixCD/etc/isdn /MorphixCD/etc/ssh \
  415.       /MorphixCD/etc/inittab /MorphixCD/etc/network /MorphixCD/etc/sudoers \
  416.       /MorphixCD/sbin/init /MorphixCD/etc/dhcpc /etc/ 2>/dev/null
  417. # Extremely important, init crashes on shutdown if this is only a link
  418. :> /etc/ioctl.save
  419. :> /etc/pnm2ppa.conf
  420. # Diet libc bug workaround
  421. cp -f /MorphixCD/etc/localtime /etc/localtime
  422. echo "${BLUE}Done.${NORMAL}"
  423.  
  424. # Now tell kernel where the real modprobe lives
  425. echo "/sbin/modprobe" > /proc/sys/kernel/modprobe
  426.  
  427. # Change root device from /dev/fd0 to /dev/ram0
  428. echo "0x100" > /proc/sys/kernel/real-root-dev
  429.  
  430. # Give control to the init process.
  431. echo "${CRE}${BLUE}Starting init process.${NORMAL}"
  432. rm -f /linuxrc
  433. exit 0
  434.  
  435. else
  436. echo "${CRE}${RED}Can't find Morphix filesystem, sorry${NORMAL}"
  437. echo "${RED}Dropping you to a (very limited) shell${NORMAL}"
  438. echo "${RED}Make sure you have a Morphix Base image on your CD-ROM"
  439. echo "${RED}Press reset button to quit.${NORMAL}"
  440. echo ""
  441. echo "Additional builtin commands avaliable:"
  442. echo "    cat        mount     umount"
  443. echo "    insmod     rmmod     lsmod"
  444. echo ""
  445. PS1="morphix# "
  446. export PS1
  447. echo "6" > /proc/sys/kernel/printk
  448. # Allow signals
  449. trap 1 2 3 15
  450. exec /static/ash
  451. fi
  452.